local console = ac.console

local models = {
    ['金币'] = [[core\tp_jb.mdl]],
    ['木材'] = [[core\tp_mt.mdl]],
    ['杀敌'] = [[core\tp_sd.mdl]],
    ['失败'] = [[core\sjsb.mdl]],
    ['成功'] = [[core\sjcg.mdl]],
}
local uis = {}
local ui_index = 0
for a=1,20 do
    local ui = class.panel.create('',500,500,1,1)
    ui.model = ui:add_model('')
    ui:set_level(9)
    uis[a] = ui
end

local skill_buttons = {}
local slots = {9,10,11,12,5,6,7,8,1,2,3,4}
local item_buttons = {}

ac.wait(1000,function()
    for a,button in ipairs(console.abilitydetail) do
        local x,y = button:get_real_position()
        local id = slots[a]
        skill_buttons[id] = {x + button.w/2,y + button.h/2,button.w,button.h}
    end
    for _,button in ipairs(console.itemdetail) do
        local x,y = button:get_real_position()
        item_buttons[button.slotid] = {x + button.w/2,y + button.h/2,button.w,button.h}
    end

end)

function show_ui_effect(player,x,y,class)
    local path = models[class]
    if player:is_self() then
        local id = ui_index%20 + 1
        local ui = uis[id]
        ui:set_real_position(x+ui.w/2,y-ui.h/2)
        ui_index = ui_index + 1
        ui.model:hide()
        ui.model:set_model(path)
        ui.model:set_animation_by_index(1)
        ui.model:show()
    end
end

function show_panel_effect(player,panel,class)
    local x,y = panel:get_real_position()
    local w,h = panel.w,panel.h
    show_ui_effect(player,x+w/2,y+h/2,class)
end

function show_item_effect(player,index,class)
    local point = item_buttons[index] or index
    local x,y = point[1],point[2]
    show_ui_effect(player,x,y,class)
end

function show_skill_tip(player,index,class)
    local point = skill_buttons[index] or index
    local x,y = point[1],point[2]
    show_ui_effect(player,x,y,class)
end
